package com.exahq.controller;


import com.exahq.common.lang.Result;
import com.exahq.entity.Companytype;
import com.exahq.entity.Industry;
import com.exahq.entity.Organizations;
import com.exahq.service.OrganizationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lhq
 * @since 2021-02-06
 */
@RestController
@RequestMapping("/organizations")
public class OrganizationsController {
    @Autowired
    OrganizationsService organizationsService;

    /**
     * 查询所有
     * @return
     */
    @RequestMapping("/finaAll")
    public Result fianall(){
        List<Organizations> list = organizationsService.list();
        return Result.succ(list);
    }
    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public Result del(@PathVariable(name = "id") Integer id) {
        return Result.succ( organizationsService.delete(id));
    }

    /**
     * 详情查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result detail(@PathVariable(name = "id") Integer id) {
        Organizations organizations = organizationsService.getById(id);
        return Result.succ(organizations);
    }
    /**
     * 增加/修改
     * @param organizations
     * @return
     */
    @PostMapping("saveEdit")
    public Result saveEdit(@RequestBody Organizations organizations){
        if (organizations!=null && !organizations.equals("")){
            if (organizations.getId() == null){
                boolean b = organizationsService.save(organizations);
                if (b){
                    return Result.succ("新添成功",b);
                }
            }else {
                if (organizationsService.saveOrUpdate(organizations))
                    return Result.succ("修改成功",organizationsService.saveOrUpdate(organizations));
            }
        }
        return Result.succ(null);
    }
}
